{% extends 'base.html' %}

{% block title %}{{ college.name }} - 学院详情{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <!-- 页面标题 -->
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h2><i class="fas fa-university"></i> {{ college.name }}</h2>
                <div>
                    <a href="{% url 'accounts:college_update' college.pk %}" class="btn btn-warning">
                        <i class="fas fa-edit"></i> 编辑
                    </a>
                    <a href="{% url 'accounts:college_delete' college.pk %}" class="btn btn-danger">
                        <i class="fas fa-trash"></i> 删除
                    </a>
                    <a href="{% url 'accounts:college_list' %}" class="btn btn-secondary">
                        <i class="fas fa-arrow-left"></i> 返回列表
                    </a>
                </div>
            </div>

            <!-- 基本信息 -->
            <div class="row mb-4">
                <div class="col-md-8">
                    <div class="card">
                        <div class="card-header">
                            <h5 class="mb-0"><i class="fas fa-info-circle"></i> 基本信息</h5>
                        </div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <p><strong>学院名称:</strong> {{ college.name }}</p>
                                    <p><strong>学院代码:</strong> <span class="badge bg-info">{{ college.code }}</span></p>
                                    <p><strong>所属学部:</strong> 
                                        {% if college.department %}
                                            <span class="badge bg-primary">{{ college.department.get_name_display }}</span>
                                        {% else %}
                                            <span class="text-muted">未分配</span>
                                        {% endif %}
                                    </p>
                                </div>
                                <div class="col-md-6">
                                    <p><strong>创建时间:</strong> {{ college.created_at|date:"Y-m-d H:i:s" }}</p>
                                    <p><strong>更新时间:</strong> {{ college.updated_at|date:"Y-m-d H:i:s" }}</p>
                                </div>
                            </div>
                            {% if college.description %}
                            <div class="row">
                                <div class="col-12">
                                    <p><strong>学院描述:</strong></p>
                                    <p class="text-muted">{{ college.description }}</p>
                                </div>
                            </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
                
                <!-- 统计信息 -->
                <div class="col-md-4">
                    <div class="card">
                        <div class="card-header">
                            <h5 class="mb-0"><i class="fas fa-chart-bar"></i> 统计信息</h5>
                        </div>
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-center mb-3">
                                <span>关联用户数</span>
                                <span class="badge bg-primary fs-6">{{ user_count }}</span>
                            </div>
                            <div class="d-flex justify-content-between align-items-center">
                                <span>关联子项目数</span>
                                <span class="badge bg-success fs-6">{{ subproject_count }}</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 关联用户 -->
            <div class="row mb-4">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h5 class="mb-0">
                                <i class="fas fa-users"></i> 关联用户 
                                <span class="badge bg-secondary">{{ user_count }}</span>
                            </h5>
                        </div>
                        <div class="card-body">
                            {% if users %}
                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>用户名</th>
                                            <th>姓名</th>
                                            <th>邮箱</th>
                                            <th>角色</th>
                                            <th>状态</th>
                                            <th>创建时间</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for user_profile in users %}
                                        <tr>
                                            <td>{{ user_profile.user.username }}</td>
                                            <td>
                                                {% if user_profile.user.first_name or user_profile.user.last_name %}
                                                    {{ user_profile.user.first_name }} {{ user_profile.user.last_name }}
                                                {% else %}
                                                    <span class="text-muted">未设置</span>
                                                {% endif %}
                                            </td>
                                            <td>{{ user_profile.user.email|default:"未设置" }}</td>
                                            <td>
                                                <span class="badge bg-info">{{ user_profile.get_role_display }}</span>
                                            </td>
                                            <td>
                                                {% if user_profile.user.is_active %}
                                                    <span class="badge bg-success">活跃</span>
                                                {% else %}
                                                    <span class="badge bg-danger">禁用</span>
                                                {% endif %}
                                            </td>
                                            <td>
                                                <small class="text-muted">{{ user_profile.created_at|date:"Y-m-d" }}</small>
                                            </td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                            {% else %}
                            <div class="text-center py-4">
                                <i class="fas fa-users fa-2x text-muted mb-3"></i>
                                <p class="text-muted">暂无关联用户</p>
                            </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>

            <!-- 关联子项目 -->
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h5 class="mb-0">
                                <i class="fas fa-project-diagram"></i> 关联子项目 
                                <span class="badge bg-secondary">{{ subproject_count }}</span>
                            </h5>
                        </div>
                        <div class="card-body">
                            {% if subprojects %}
                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>子项目名称</th>
                                            <th>所属项目</th>
                                            <th>负责人</th>
                                            <th>使用经费</th>
                                            <th>状态</th>
                                            <th>创建时间</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for subproject in subprojects %}
                                        <tr>
                                            <td>
                                                <a href="{% url 'subprojects:detail' subproject.pk %}" class="text-decoration-none">
                                                    {{ subproject.name }}
                                                </a>
                                            </td>
                                            <td>
                                                <a href="{% url 'projects:detail' subproject.project.pk %}" class="text-decoration-none">
                                                    {{ subproject.project.name }}
                                                </a>
                                            </td>
                                            <td>{{ subproject.manager }}</td>
                                            <td>
                                                <span class="text-success">¥{{ subproject.used_budget|floatformat:2 }}</span>
                                            </td>
                                            <td>
                                                <span class="badge bg-{{ subproject.status_color }}">
                                                    {{ subproject.get_status_display }}
                                                </span>
                                            </td>
                                            <td>
                                                <small class="text-muted">{{ subproject.created_at|date:"Y-m-d" }}</small>
                                            </td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                            {% else %}
                            <div class="text-center py-4">
                                <i class="fas fa-project-diagram fa-2x text-muted mb-3"></i>
                                <p class="text-muted">暂无关联子项目</p>
                            </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}